/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Common.Constant;
import Helper.ItemHelper;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author KIENLT
 */
public class ItemModel extends AbstractTableModel {
    ArrayList<ItemHelper> ItemList;
    
    private final String colunmsName[] = { Constant.getBundle().getString("Id"), Constant.getBundle().getString("Iname"), Constant.getBundle().getString("Price"), Constant.getBundle().getString("Quantity"), Constant.getBundle().getString("Cname") };
    private final Class columnsClass[] = { String.class, String.class, String.class, String.class, String.class };
    
    public ItemModel(ArrayList<ItemHelper> ItemList){
        this.ItemList = ItemList;
    }
    
    @Override
    public int getRowCount() {
        return ItemList.toArray().length;
    }

    @Override
    public int getColumnCount() {
        return colunmsName.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 0 : 
                return ItemList.get(rowIndex).getId();
            case 1 : 
                return ItemList.get(rowIndex).getName();
            case 2 :
                return ItemList.get(rowIndex).getPrice();
            case 3 :
                return ItemList.get(rowIndex).getQuantity();
            case 4 :
                return ItemList.get(rowIndex).getCategoryName();
            default: 
                return null;
        }
    }
    
    @Override
    public void setValueAt(Object obj, int row, int col) {
        switch (col) {
            case 0:
                //BillsList.get(row).setId(String.valueOf(obj));
                break;
            case 1:
                //BillsList.get(row).setItemName(String.valueOf(obj));
                break;
            case 2:
                //BillsList.get(row).setPrice(String.valueOf(obj));
                break;
            case 3:
                ItemList.get(row).setQuantity(String.valueOf(obj));
                break;
            case 4:
                //BillsList.get(row).setTotal(String.valueOf(obj));
                break;
            default:
                ;
        }
    }
    
    @Override
    public String getColumnName(int icol){
        return colunmsName[icol];
    }
    
    @Override
    public Class getColumnClass(int icol){
        return columnsClass[icol];
    }
    
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return true;
    }
    
    public void deleteRow(int deleteRow) {
        ItemList.remove(deleteRow);
        ItemList.trimToSize();
        fireTableRowsDeleted(deleteRow, deleteRow);
    }
}
